package com.sugon.entity;

import cn.afterturn.easypoi.excel.annotation.Excel;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;

/**
 * 领料单详细实体
 * 表名 MATERIAL_RECORD
 *
 * @author YuXD
 * @date 2020-12-21 13:59
 */
@Data
public class MaterialRecordEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 领料仓库
     */
    private String store;

    @Excel(name = "仓库名称", width = 20, orderNum = "9")
    private String storeName;

    private String storeCode;

    /**
     * 领料单
     */
    @Excel(name = "领料单号", width = 20, orderNum = "4")
    private String material;

    /**
     * 仓库位置
     */
    @Excel(name = "备件位置", width = 25, orderNum = "10")
    private String postion;
    /**
     * 仓库关联数据保存 与SpareStorePostEntity/ToolsStorePostEntity关联
     */
    private String postionId;

    /**
     * 申请
     */
    private Integer num;

    /**
     * 实发数
     */
    @Excel(name = "领用数", width = 10, orderNum = "11", type = 10)
    private Integer actualNum;

    /**
     * 领料后实际使用数
     */
    @Excel(name = "更换数", width = 10, orderNum = "12", type = 10)
    private Integer replaceNum;

    /**
     * 备件、工装编码
     */
    @Excel(name = "备件编码", width = 15, orderNum = "1")
    private String spareCode;

    /**
     * 备件、工装名称
     */
    @Excel(name = "备件名称", width = 25, orderNum = "2")
    private String spareName;

    /**
     * 供应厂商名称
     */
    private String producerName;

    /**
     * 主键
     */
    private String id;

    /**
     * 删除标识 0: 已删除  1：未删除
     */
    private Integer delFlag;

    /**
     * 是否处理
     */
    private Integer isOk;

    /**
     * 部门编码
     */
    private String deptCode;
    /****************VO字段，关联查询获取********************/

    /**
     * 领用单位名称
     */
    @Excel(name = "领用部门", width = 20, orderNum = "5")
    private String deptName;

    /**
     * 维修或维护工单号
     */
    private String jobCode;

    /**
     * 领料申请人姓名
     */
    @Excel(name = "申请人", width = 10, orderNum = "6")
    private String pickerName;

    /**
     * 用途
     */
    @Excel(name = "用途", width = 30, orderNum = "8")
    private String purpose;

    /**
     * 领用申请日期
     */
    @Excel(name = "申请时间", width = 25, orderNum = "7", format = "yyyy-MM-dd HH:mm")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
    private Date pickDate;

    /**
     * 领料单类型
     */
    private Integer materialType;

    /**
     * 备件ID
     */
    private String spareId;

    /**
     * 备件规格
     */
    @Excel(name = "备件规格", width = 40, orderNum = "3")
    private String spec;

    /**
     * ERP编码
     */
    private String erpCode;

    /**
     * ERP编码
     */
    private String partCode;

    /**
     * 库存数量
     */
    private Integer storeNum;

    /**
     * 锁定数量
     */
    private Integer locNum;

    /**
     * 获取当前领料明细的可更换数
     * 实际领料数 - 已更换的数
     *
     * @return
     */
    public Integer getReplacableNum() {
        if (getActualNum() == null || getReplaceNum() == null) {
            return 0;
        }
        Integer replacableNum = getActualNum() - getReplaceNum();
        if (replacableNum < 0) {
            replacableNum = 0;
        }
        return replacableNum;
    }

}
